Skip to content

feat(rewards-program): add points system#22

Merged
amilz merged 15 commits intomainfrom
feat/add-points-reward
Mar 31, 2026
Merged

feat(rewards-program): add points system#22
amilz merged 15 commits intomainfrom
feat/add-points-reward

Conversation

@amilz
Copy link
Copy Markdown
Collaborator

@amilz amilz commented Mar 23, 2026

Summary

  • Adds points as a fourth distribution paradigm — pure u64 PDA ledger, no token programs
  • 7 instructions: init_points, issue_points, use_points, transfer_points, close_points_account, close_points_config, revoke_points
  • 2 new accounts: PointsConfig, UserPointsAccount
  • Authority issues/revokes/closes; user cosigns use and transfer
  • Configurable: transferable flag, max_supply (0=unlimited), revocable flag

Test plan

  • 427 unit tests passing (program)
  • 406 integration tests passing (fixtures + business logic + lifecycle)
  • cargo clippy -D warnings clean on program and tests
  • cargo fmt --check clean
  • IDL regenerated and clients updated

Closes TOO-197

@amilz amilz requested a review from dev-jodee March 23, 2026 17:01
@amilz amilz self-assigned this Mar 23, 2026
Copy link
Copy Markdown
Collaborator

@dev-jodee dev-jodee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good

amilz added a commit that referenced this pull request Mar 30, 2026
- Enrich all points events with full config fields (authority, seed,
  max_supply, transferable, revocable, total_issued, total_used) so
  indexers don't need extra account fetches
- Add self-transfer guard in transfer_points to prevent from_account
  write being clobbered by to_account write on same PDA
- Add validate_zero_balance() helper on UserPointsAccount, use in
  close_points_account
- Replace ExpectedPointsConfig struct with individual params in test
  assertions for consistency with existing patterns
- Regenerate IDL and clients
@dev-jodee dev-jodee self-requested a review March 30, 2026 19:08
dev-jodee
dev-jodee previously approved these changes Mar 30, 2026
Copy link
Copy Markdown
Collaborator

@dev-jodee dev-jodee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a couple of nits but rest looks good

amilz added a commit that referenced this pull request Mar 30, 2026
- Enrich all points events with full config fields (authority, seed,
  max_supply, transferable, revocable, total_issued, total_used) so
  indexers don't need extra account fetches
- Add self-transfer guard in transfer_points to prevent from_account
  write being clobbered by to_account write on same PDA
- Add validate_zero_balance() helper on UserPointsAccount, use in
  close_points_account
- Replace ExpectedPointsConfig struct with individual params in test
  assertions for consistency with existing patterns
- Regenerate IDL and clients
@amilz amilz force-pushed the feat/add-points-reward branch from 9a72df4 to 8c8999f Compare March 30, 2026 20:01
amilz added a commit that referenced this pull request Mar 30, 2026
- Refactor cpi_* free functions into PointsCpi struct (dev-jodee)
- Remove unused _system_program param from initialize_points_mint
- Move ATA validation from processors into accounts.rs
- Error on zero-balance revoke with PointsNothingToRevoke
@amilz amilz requested a review from dev-jodee March 30, 2026 21:04
amilz added 15 commits March 31, 2026 08:07
Add points type as fourth distribution paradigm — pure u64 PDA ledger
with no token programs. Authority issues/closes, user cosigns use/transfer.

Accounts: PointsConfig, UserPointsAccount
Instructions: init_points, issue_points, use_points, transfer_points,
close_points_account, close_points_config
Authority can force-burn a user's points and close their account when
config.revocable is set. Gated on validate_revocable check. Revoked
balance counted as used. Also adds intentional-design comment to
close_points_config explaining admin authority over lifecycle.
7 fixture files, 8 test files covering all points instructions.
Includes generic constraint tests, business logic error paths,
PDA mismatch validation, and end-to-end lifecycle test.
- Enrich all points events with full config fields (authority, seed,
  max_supply, transferable, revocable, total_issued, total_used) so
  indexers don't need extra account fetches
- Add self-transfer guard in transfer_points to prevent from_account
  write being clobbered by to_account write on same PDA
- Add validate_zero_balance() helper on UserPointsAccount, use in
  close_points_account
- Replace ExpectedPointsConfig struct with individual params in test
  assertions for consistency with existing patterns
- Regenerate IDL and clients
Add helpers on state structs to replace raw checked arithmetic in
processors: add_balance, sub_balance, add_issued, add_used,
validate_zero_balance. Processors now read as clean intent rather
than manual field manipulation.
Add 13 new integration tests covering missing error paths, edge cases,
and cross-instruction flows for the points system.
… in close_points_account

- Add explicit points_mint PDA validation to all 6 post-init processors
  (defense-in-depth against mint substitution)
- close_points_account now actually closes the user's ATA via Token-2022
  CloseAccount CPI (user signs as account owner, receives rent refund)
- Clarify POINTS_MINT_SPACE comment with full layout breakdown
- Refactor cpi_* free functions into PointsCpi struct (dev-jodee)
- Remove unused _system_program param from initialize_points_mint
- Move ATA validation from processors into accounts.rs
- Error on zero-balance revoke with PointsNothingToRevoke
Points::initialize, Points::issue, Points::burn, Points::close_account,
Points::close_mint, Points::create_account
@amilz amilz force-pushed the feat/add-points-reward branch from 202e6b0 to 3426630 Compare March 31, 2026 15:09
@amilz amilz merged commit 1b47f5f into main Mar 31, 2026
7 checks passed
@amilz amilz deleted the feat/add-points-reward branch March 31, 2026 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants